// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.*;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLCreateTriggerStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "SQLExprTableSource.h"

SQLCreateTriggerStatement_TriggerType_ptr SQLCreateTriggerStatement_TriggerType::BEFORE = SQLCreateTriggerStatement_TriggerType_ptr(new SQLCreateTriggerStatement_TriggerType(1 << 0, make_string_ptr("BEFORE")));
SQLCreateTriggerStatement_TriggerType_ptr SQLCreateTriggerStatement_TriggerType::AFTER = SQLCreateTriggerStatement_TriggerType_ptr(new SQLCreateTriggerStatement_TriggerType(1 << 1, make_string_ptr("AFTER")));
SQLCreateTriggerStatement_TriggerType_ptr SQLCreateTriggerStatement_TriggerType::INSTEAD_OF = SQLCreateTriggerStatement_TriggerType_ptr(new SQLCreateTriggerStatement_TriggerType(1 << 2, make_string_ptr("INSTEAD_OF")));

SQLCreateTriggerStatement_TriggerType::SQLCreateTriggerStatement_TriggerType(uint64_t mask, string_ptr name)
{
  this->mask = mask;
  this->name = name;
}

SQLCreateTriggerStatement_TriggerEvent_ptr SQLCreateTriggerStatement_TriggerEvent::INSERT = SQLCreateTriggerStatement_TriggerEvent_ptr(new SQLCreateTriggerStatement_TriggerEvent(1 << 0, make_string_ptr("INSERT")));
SQLCreateTriggerStatement_TriggerEvent_ptr SQLCreateTriggerStatement_TriggerEvent::UPDATE = SQLCreateTriggerStatement_TriggerEvent_ptr(new SQLCreateTriggerStatement_TriggerEvent(1 << 1, make_string_ptr("UPDATE")));
SQLCreateTriggerStatement_TriggerEvent_ptr SQLCreateTriggerStatement_TriggerEvent::DELETE = SQLCreateTriggerStatement_TriggerEvent_ptr(new SQLCreateTriggerStatement_TriggerEvent(1 << 2, make_string_ptr("DELETE")));

SQLCreateTriggerStatement_TriggerEvent::SQLCreateTriggerStatement_TriggerEvent(uint64_t mask, string_ptr name)
{
  this->mask = mask;
  this->name = name;
}

SQLCreateTriggerStatement::SQLCreateTriggerStatement()
{
  updateOfColumns = std::make_shared<std::list<SQLName_ptr>>();
}

SQLCreateTriggerStatement::SQLCreateTriggerStatement(DbType_ptr dbType)
    : SQLStatementImpl(dbType)
{
}

void SQLCreateTriggerStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLCreateTriggerStatement)))
  {
    acceptChild(visitor, name);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLName, SQLObject>(updateOfColumns);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, on);
    acceptChild(visitor, when);
    acceptChild(visitor, body);
  }
  visitor->endVisit(SharedObject(SQLCreateTriggerStatement));
}

// @Override
SQLObject_list_ptr SQLCreateTriggerStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  if (name != nullptr)
  {
    children->push_back(name);
  }
  // children.addAll(updateOfColumns);
  for (auto it : *updateOfColumns)
  {
    children->push_back(it);
  }
  if (on != nullptr)
  {
    children->push_back(on);
  }
  if (when != nullptr)
  {
    children->push_back(when);
  }
  if (body != nullptr)
  {
    children->push_back(body);
  }
  return children;
}

SQLExprTableSource_ptr SQLCreateTriggerStatement::getOn()
{
  return on;
}

void SQLCreateTriggerStatement::setOn(SQLName_ptr on)
{
  this->setOn(SQLExprTableSource_ptr(new SQLExprTableSource(on)));
}

void SQLCreateTriggerStatement::setOn(SQLExprTableSource_ptr on)
{
  if (on != nullptr)
  {
    on->setParent(SharedObject(SQLCreateTriggerStatement));
  }
  this->on = on;
}

SQLName_ptr SQLCreateTriggerStatement::getName()
{
  return name;
}

void SQLCreateTriggerStatement::setName(SQLName_ptr name)
{
  if (name != nullptr)
  {
    name->setParent(SharedObject(SQLCreateTriggerStatement));
  }
  this->name = name;
}

SQLStatement_ptr SQLCreateTriggerStatement::getBody()
{
  return body;
}

void SQLCreateTriggerStatement::setBody(SQLStatement_ptr body)
{
  if (body != nullptr)
  {
    body->setParent(SharedObject(SQLCreateTriggerStatement));
  }
  this->body = body;
}

BOOL_ptr SQLCreateTriggerStatement::isOrReplace()
{
  return orReplace;
}

void SQLCreateTriggerStatement::setOrReplace(BOOL_ptr orReplace)
{
  this->orReplace = orReplace;
}

SQLCreateTriggerStatement_TriggerType_ptr SQLCreateTriggerStatement::getTriggerType()
{
  return triggerType;
}

void SQLCreateTriggerStatement::setTriggerType(SQLCreateTriggerStatement_TriggerType_ptr triggerType)
{
  this->triggerType = triggerType;
}

SQLCreateTriggerStatement_TriggerEvent_list_ptr SQLCreateTriggerStatement::getTriggerEvents()
{
  return nullptr;
}

BOOL_ptr SQLCreateTriggerStatement::isForEachRow()
{
  return forEachRow;
}

void SQLCreateTriggerStatement::setForEachRow(BOOL_ptr forEachRow)
{
  this->forEachRow = forEachRow;
}

SQLName_list_ptr SQLCreateTriggerStatement::getUpdateOfColumns()
{
  return updateOfColumns;
}

SQLExpr_ptr SQLCreateTriggerStatement::getWhen()
{
  return when;
}

void SQLCreateTriggerStatement::setWhen(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLCreateTriggerStatement));
  }
  this->when = x;
}

BOOL_ptr SQLCreateTriggerStatement::isUpdate()
{
  return update;
}

void SQLCreateTriggerStatement::setUpdate(BOOL_ptr update)
{
  this->update = update;
}

BOOL_ptr SQLCreateTriggerStatement::isDelete()
{
  return delete_;
}

void SQLCreateTriggerStatement::setDelete(BOOL_ptr delete_)
{
  this->delete_ = delete_;
}

BOOL_ptr SQLCreateTriggerStatement::isInsert()
{
  return insert;
}

void SQLCreateTriggerStatement::setInsert(BOOL_ptr insert)
{
  this->insert = insert;
}

SQLName_ptr SQLCreateTriggerStatement::getDefiner()
{
  return definer;
}

void SQLCreateTriggerStatement::setDefiner(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLCreateTriggerStatement));
  }
  this->definer = x;
}

// @Override
SQLDDLStatement::DDLObjectType SQLCreateTriggerStatement::getDDLObjectType()
{
  return SQLDDLStatement::DDLObjectType::TRIGGER;
}
